<?php
/**
 * @todo 功能函数
 * @copyright gaoxiang 2009
 * @author gaoxiang
 * @createdate 2009.03.17
 * @license 本程序遵照Creative Commons 署名-非商业性使用-相同方式共享 2.5 中国大陆 协议，该协议的中文版本可在http://creativecommons.org/licenses/by-nc-sa/2.5/cn/下查看。
 **/
/*html头信息*/
function html_header()
{
	session_start();
	global $database;
	$_SESSION['header']=1;
	 ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>金龙集团铝管事业部数据系统</title>
	<meta name="description" content="金龙集团铝管事业部数据系统" />
	<link rel="stylesheet" type="text/css" href="<?php echo $database->arr_config_r[0]; ?>css/style.css" media="all" />
	<!--[if lte IE 6]>
<style type="text/css">
/* styling specific to Internet Explorer IE5.5 and IE6. Yet to see if IE7 handles li:hover */

/* Get rid of any default table style */
.menu table {
border-collapse:collapse;
margin:-1px;
}
/* ignore the link used by 'other browsers' */
.menu ul li a.hide, .menu ul li a:visited.hide {
display:none;
}
/*隐藏一个东西*/
.menu .hide {display:none;}
/* set the background and foreground color of the main menu link on hover */
.menu ul li a:hover {
color:#fff;
background:#000;
}
/* make the sub menu ul visible and position it beneath the main menu list item */
.menu ul li a:hover ul {
display:block;position:absolute;top:23px;left:0;width:100%;border-top:1px solid #fff;
}
/* style the background and foreground color of the submenu links */
.menu ul li a:hover ul li a {
display:block;background:#757575;color:#fff;height:auto;line-height:16px;padding:5px 16px 5px 16px;width:120px;
}
/* style the background and forground colors of the links on hover */
.menu ul li a:hover ul li a:hover {
background:#202D3D;color:#fff;
}
</style>
<![endif]-->
<?php
	$phpshell=basename($_SERVER['PHP_SELF']);
	if($phpshell=='produce.php'){?>
		<script language="javascript" type="text/javascript" src="<?php echo $database->arr_config_r[0]; ?>js/query.js"></script>
		<?php if($_GET['action']=='prequery_edit' || $_GET['action']=='prequery'){?>
		<script type="text/javascript" src="<?php echo $database->arr_config_r[0]; ?>datepicker/WdatePicker.js"></script><?php }?>
		<script type="text/javascript" src="<?php echo $database->arr_config_r[0]; ?>js/sorttable.js"></script> <!--不要忘记合并js -->
	<?php }
	elseif($phpshell=='rog.php'){?>
		<script language="javascript" type="text/javascript" src="<?php echo $database->arr_config_r[0]; ?>js/rog.js"></script>
		<?php if($_GET['action']=='prequery_edit' || $_GET['action']=='prequery'){ ?>
		<script type="text/javascript" src="<?php echo $database->arr_config_r[0]; ?>datepicker/WdatePicker.js"></script><?php }?>
		<script type="text/javascript" src="<?php echo $database->arr_config_r[0]; ?>js/sorttable.js"></script> <!--不要忘记合并js -->
	<?php }
	elseif($phpshell=='login.php'){?>
		<script language="javascript" type="text/javascript" src="<?php echo $database->arr_config_r[0]; ?>js/login.js"></script>
	<?php }
	elseif($phpshell=='checkxls.php'){?>
		<script src="<?php echo $database->arr_config_r[0]; ?>js/jquery.js" type="text/javascript"></script>
		<script src="<?php echo $database->arr_config_r[0]; ?>js/jquery.filestyle.js" type="text/javascript"></script>
	<?php }?>
 </head>
 <body id="body" onload="startclock()">
	<div id="page">
	<div id="logo"><img src="<?php echo $database->arr_config_r[0]; ?>images/logo2.jpg" alt="金龙集团铝管事业部数据系统" /><span><h1> 金龙集团铝管事业部数据系统</h1></span>
	<div class="menucontainer">
	<div class="menu">
	<ul>
		<li>
            <a href="<?php echo $database->arr_config_r[0]; ?>" target="_self">首页</a>  
        </li>
        <li>
            <a href="#" target="_self" style="border-style:none;">生产 
				<table><tr><td><ul>
						<li><a href="<?php echo $database->arr_config_r[0] . "action/produce.php?action=prequery";?>" target="_self">生产记录查询</a></li>
						<?php if(check_rights(2,0)){//如果用户有生产权限
						echo '<li><a href="' . $database->arr_config_r[0] . 'action/produce.php?action=prequery_edit" target="_self">生产记录修改</a></li>
						<li><a href="' . $database->arr_config_r[0] . 'action/produce.php?action=prepare_edit" target="_self">生产记录输入</a></li>
						<li><a href="' . $database->arr_config_r[0] . 'action/leadupload.php?action=product" target="_self">生产记录导入</a></li>';}
						if(check_rights(1,0)){//如果用户有技术权限
							$inspection=$database->fetch_inspection(1);
							if($inspection)
								echo '<li><a href="'. $database->arr_config_r[0] . 'action/produce.php?action=inspection">待检品(' . $inspection . ')</a></li>';
						}
						?>
				</ul></td></tr></table></a>
		</li>
        <li>
            <a href="#" target="_self">原材料  
            	<table><tr><td><ul>
                        <li><a href="<?php echo $database->arr_config_r[0] . "action/rog.php?action=prequery";?>" target="_self">原材料记录查询</a></li>
                        <?php if(check_rights(4,0)){//如果用户有原材料权限
							echo '<li><a href="' . $database->arr_config_r[0] . 'action/rog.php?action=prequery_edit" target="_self">原材料记录修改</a></li>
						<li><a href="' . $database->arr_config_r[0] . 'action/rog.php?action=preinput" target="_self">原材料记录输入</a></li>
						<li><a href="' . $database->arr_config_r[0] . 'action/leadupload.php?action=rog" target="_self">原材料记录导入</a></li>';}?>
             	</ul></td></tr></table></a> 
        </li>
				<li>
            <a href="#" target="_self">实验室
            	<table><tr><td><ul>
                        <li><a href="<?php echo $database->arr_config_r[0] . "index.php";?>" target="_self">占位</a></li>
              </ul></td></tr></table></a> 
        </li>
				<li>
            <a href="#" target="_self">其他
            	<table><tr><td><ul>
                        <li><a href="<?php echo $database->arr_config_r[0] . "tools/index.php";?>" target="_self">常用工具及信息</a></li>
              </ul></td></tr></table></a> 
        </li>
        <?php if (isset($_SESSION["userid"]) && isset($_SESSION["rights"])){?>			
			<li class="hide" style="margin-left: 315px;"><a href="<?php echo $database->arr_config_r[0] . "admin/login.php?log=logout"; ?>">注销</a></li>
			<!--[if lte IE 6]>
				<li style="margin-left: 315px;"><a href="<?php echo $database->arr_config_r[0] . "admin/login.php?log=logout"; ?>">注销</a></li>
			<![endif]-->
			<li><a href="<?php echo $database->arr_config_r[0] . "admin/login.php?log=passalter"; ?>">修改密码</a></li>
			<?php }else{ ?>
	<li class="hide" style="margin-left: 410px;"><a href="<?php echo $database->arr_config_r[0] . "admin/login.php?log=login"; ?>">登陆</a></li>
	<!--[if lte IE 6]>
		<li style="margin-left: 380px;"><a href="<?php echo $database->arr_config_r[0] . "admin/login.php?log=login"; ?>">登陆</a></li>
	<![endif]-->
<?php }?>
	<li><a href="<?php echo $database->arr_config_r[0] . "doc/help.php"; ?>">帮助</a></li>
	</ul>
	</div></div></div>	<div style="clear: both;">&nbsp;</div>
    
<?php 
}
	

/*输出页脚*/
function html_footer(){
	global $database;
	unset($_SESSION['header']);
	?>
	<script language="javascript">
var timerID=null;var timerRunning=false;function stopclock(){if(timerRunning){clearTimeout(timerID)}timerRunning=false}function startclock(){stopclock();showtime()}function showtime(){var c=new Date();var f=c.getFullYear();var g=c.getMonth()+1;var b=c.getDate();var a=c.getHours();var d=c.getMinutes();var h=c.getSeconds();var e=f+"-"+g+"-"+b+" "+a;e+=((d<10)?":0":":")+d;e+=((h<10)?":0":":")+h;document.clock.thetime.value=e;timerID=setTimeout("showtime()",1000);timerRunning=true};
</script>
		<div style="clear: both;">&nbsp;</div></div>
		<div id="foot"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/"><img src="<?php echo $database->arr_config_r[0]; ?>images/by-nc-sa.png" style="border-style:none;" /></a><br />
		GDcopper Aluminum Tube Division Data System dev2<br />
			Powerd by gaoxiang from Laboratory
		<form name="clock" >
		<input name="thetime" style="font-size: 14px;color:#000000;border:0;width:150px" size="12" readonly/>
		</form></div></body></html>
<?php }
	/*保存来源地址*/
function set_refer(){
	if(empty($_SERVER['HTTP_REFERER'])){
		$_SESSION['referer'] = $database->arr_config_r[0];
	}else{
		$_SESSION['referer'] = $_SERVER['HTTP_REFERER'];
	}
 }
/* 登陆 */
function login_to(){
	global $database;
	?>
	<div class="log">
		<form action="login.php?log=login&action=submit" onsubmit="return check_login()" method="post">
			<fieldset>
				<legend align="center">登陆系统</legend>
				<table cellpadding="10px">
				<tr><td><label for="user">用户名</label></td><td><input name="user" class="username" id="user" maxlength="20" /></td></tr>
				<tr><td><label for="pass">密码</label></td><td><input name ="pass" class="password" id="pass" type="password" /></td><td class="noline"><a href="<?php echo $database->arr_config_r[0] . "admin/login.php?log=passalter";?>">修改密码</a></td></tr>
				<tr><td></td><td style="text-align:right">
				<input type="checkbox" style="width:20px;margin-bottom:3px" name="cookietime" value="1"/>保存一周</td></tr>
				<tr><td></td><td style="text-align:center;">
				<button type="submit" class="positive">登 陆</button></td></tr>
				</table>
			</fieldset>
		</form>
		</div>
<?php 	html_footer();}

/* 修改密码 */
function pass_alter(){
	?>
	<div class="log">
	<fieldset>
	<legend align="center">修改密码</legend>
		<form action="login.php?log=passalter&action=submit" onsubmit="return check_alter()" method="post">
			<table>
			<tr><td><label for="pass">原密码</label></td><td><input name ="pass" id="pass_1" type="password" /></td></tr>
			<tr><td><label for="pass1">新密码</label></td><td><input name ="pass1" id="pass_2" type="password" /></td></tr>
			<tr><td><label for="pass2">重复新密码</label></td><td><input name ="pass2" id="pass_3" type="password" /></td></tr>
			<tr><td><br /></td></tr>
			<tr><td></td><td style="text-align:center"><button type="submit" class="positive">修 改</button></td></tr>
			</table>
		</form>
		</fieldset>
	</div>
<?php 	html_footer();}

/**	@todo 页面跳转
 * 	参数  跳回地址，说明文字
 * 	直接在网页上显示
 * 
 **/
 function login_echo($referer,$echo_var){
 	global $database;
	if(isset($_SESSION['userid']) && isset($_SESSION['rights'])){
		$referer1=explode('?',$referer);
		$referer2=$database->arr_config_r[0]. "admin/login.php";
		if($referer1[0]==$referer2)
			$referer=$database->arr_config_r[0];
	}
	if(!isset($_SESSION['header']))
		html_header();
 	header("refresh:3;url= " . $referer);
	echo "<div class=\"center-text\"> $echo_var <br />如果浏览器没有跳转，请点击<a href=\"$referer\">这里</a></div>";
	html_footer();
	exit;
 }
 
/**	@todo 跳转到上一页面
 * 	参数  跳回地址，说明文字
 * 	直接在网页上显示
 * 
 **/
 function back_prior($echo_var){ 
	 header('Cache-control: private, must-revalidate');
	 ?>
	 <script language="javascript"> function return_f(){javascript:history.go(-1);} setTimeout('return_f()',2000);</script>
 	<div class="center-text"><?php echo $echo_var ;?><br />如果浏览器没有跳转，请点击<a href="javascript:history.go(-1)">这里</a>返回</div><?php	
	 html_footer();	
	 exit;
 }
  
/**	@todo 生产查询表单
 * 	参数  开始时间，结束时间，客户，规格，投料，班组，机组，模具，判定结果，均为必填项
 * 	直接在网页上显示
 * 
 **/

 function produce_form($pbegin,$pend,$pclient,$pspec,$prog,$pmachine,$pclass,$pgroup,$pmould,$pjudge,$is_edit){
 	global $arr_spec,$database;
	 ?>
 	<div class="log">
 	<fieldset>
 	<legend align="center"><?php if($is_edit) echo '修改范围'; else echo '生产记录查询';?></legend><table>
 			<form id="pform"  action="<?php echo $database->arr_config_r[0];?>action/produce.php?action=<?php if($is_edit) echo 'product_edit_';?>query" onsubmit="return check_form()" method="post"> <!--发送数据到..-->
		  		<tr><td><label for="pbegin">日期*</label></td>
				  <td><input name="pbegin" type="text" id="pbegin" value="<?php echo $pbegin;?>" onfocus="WdatePicker({isShowClear:false,readOnly:true})" size="10" maxlength="10" /></td><td><label for="pend" style="text-align:center">至</label></td>
		  		<td><input name="pend" type="text" id="pend" value="<?php echo $pend;?>" onfocus="WdatePicker({isShowClear:false,readOnly:true})" size="10" maxlength="10" readonly="readonly"/></td></tr>
		  		<tr><td><label for="pmachine">机</label></td><td><select style="text-align:center;" name="pmachine" id="pmachine" onchange="select_group('<?php echo $pmachine;?>')" >
					<option value="00" <?php if ($pmachine==0) echo "selectd";?>>全部</option>
					<option value="01">01</option>
					<option value="02">02</option>
					<option value="03">03</option>
					<option value="04">04</option>
					<option value="05">05</option>
					<option value="06">06</option>
					<option value="07">07</option>
					<option value="08">08</option>
					<option value="09">09</option>
					<option value="10">10</option>
					<option value="11">11</option>
				</select></td></tr>
		  		<tr><td><label for="pclass">班</label></td><td><select style="text-align:center;" name="pclass" id="pclass" onchange="select_group('<?php echo $pgroup;?>')" >
					<option value="0" <?php if ($pclass==0) echo "selectd";?>>全部</option>
					<option value="1">A</option>
					<option value="2">B</option>
					<option value="3">C</option>
				</select></td></tr>
				<tr><td><label for="pgroup">组</label></td><td><select style="text-align:center;" name="pgroup" id="pgroup" <?php if ($pclass==0) echo "disabled";?>>
					<option value="0" <?php if ($pgroup==0) echo "selectd";?>>全部</option>
					<option value="1">A</option>
					<option value="2">B</option>
					<option value="3">C</option>
					<option value="4">D</option>
					<option value="5">E</option>
					<option value="6">F</option>
					<option value="7">G</option>
					<option value="8">H</option>
					<option value="9">I</option>
					<option value="10">J</option>
					<option value="11">K</option>	
				</select></td></tr>
				  <tr><td><label for="pclient">客户</label></td>
				<td><input name="pclient" type="text" style="text-align:center;" value="<?php echo $pclient;?>" maxlength="40" size="4"/></td></tr>
				<tr><td><label for="pspec">规格</label></td>
				<td><select name="pspec" style="text-align:center;">
					<option value="0" <?php if ($pspec==0) echo "selectd";?>>全部</option>
					<?php
					$i=0; 
					while (isset($arr_spec[$i])){ ?>
						<option value="<?php echo $arr_spec[$i];?>" <?php if ($pspec==$arr_spec[$i]) echo "selectd";?>><?php echo $arr_spec[$i];?></option>
					<?php ++$i;} ?>	
				</select></td></tr>					
				<tr><td><label for="prog">投料批号</label></td>
				<td><input name="prog" type="text" id="prog" style="text-align:center;" value="<?php echo $prog;?>" maxlength="12" size="12"/></td></tr>
				<tr><td><label for="pmould">模具</label></td>
				<td><input name="pmould" type="text" id="pmould" style="text-align:center;" value="<?php echo $pmould;?>" maxlength="3" size="3"/></td></tr>
				<tr><td><label for="pjudge">判定结果</label></td>
				<td><select style="text-align:center;" name="pjudge" >
					<option value="0" <?php if ($pjudge==0) echo "selectd";?>>全部</option>
					<option value="合格">合格</option>
					<option value="不合格">不合格</option>
					<option value="待检">待检</option>
				</select></td></tr>
				<tr><td></td><td></td><td><button type="submit" class="positive">提 交</button></td></tr>
			</form>
			</table>
			</fieldset>			 		
		 </div>
 	<?php }

/**	@todo 生产修改查询表单
 * 	参数  开始时间，结束时间，客户，规格，投料，班组，机组，模具，判定结果，均为必填项
 * 	直接在网页上显示
 * 
 **/

 function produce_edit_form(){
 	global $database;
	 ?>
 	<div class="log">
 	<fieldset>
 	<legend align="center">修改记录</legend><table>
 			<form id="pform"  action="<?php echo $database->arr_config_r[0];?>action/produce.php?action=product_edit" method="post"> <!--发送数据到..-->			
				<tr><td><label for="product">产品批号</label></td>
				<td><input name="product" type="text" id="product" style="text-align:center;" maxlength="12" size="12"/></td><td class="noline"><a href="<?php echo $database->arr_config_r[0];?>action/produce.php?action=product_edit_allinput">查找更多?</a></td></tr>
				<tr><td></td><td>
				<button type="submit" class="positive">提 交</button></tr>
			</form>
			</table>
			</fieldset>			 		
		 </div>
 	<?php }




/** @todo 格式化日期并与另一个日期比较(没有时间)
*	参数xx(年)xx(月)xx(日),一个UNIX时间戳
*	相同返回true
**/
function compare_date($str,$datetime){
	$date_sub=substr($str,0,2) .'-' . substr($str,2,2) .'-' . substr($str,4,2);
	$date_sub2=date('Y-m-d',strtotime($date_sub));
	$datetime2=date('Y-m-d',$datetime);
	if(strcmp($date_sub2,$datetime2)==0){
		return true;
	}else{
		return false;
}}

/** @todo 格式化日期
*	参数xxxx-xx-xx
*	输出xxxxxx
**/
function datetostring($date){
	$string = substr($date,2,2);
	$string .= substr($date,5,2);
	$string .= substr($date,8,2);
	return $string;
}

/** @todo 获取一月的天数
*	参数：年，月（1-12之间)
* 
**/
function  get_days($year,$month){
	if ($month==2){
		if (($year % 4)==0 && ($year % 400==0 ||$year % 100 != 0)){
			$days = 29;
		}else{
			$days = 28;
		}
	}elseif($month == 1 || $month == 3 || $month == 5 || $month == 7 || $month == 8 || $month == 10 || $month == 12 ){
		$days = 31;
	}else{
		$days = 30;
		}
	return $days;	
	}
	
/** @todo 校验日期格式
*	参数：string
* 	如果日期格式为xxxx-xx-xx或者xxxx/xx/xx为真
**/
function is_date($str,$format="Y-m-d"){
        $str = trim($str);
        $unixTime = strtotime($str);
        $checkDate = date($format,$unixTime);
        if(strcmp($checkDate,$str) == 0){
                return true;
        }else{
                return false;
        }
}
/* 检测是否为单个字母，不区分大小写
参数：$char 为单个字母
返回true or false*/
function is_char($char) {
	$char_re='/[a,z]/i';
	if(preg_match($char_re,$char))
		return true;
	else {
		Return false;
	}
}

/** @todo 输出查询结果表头
 *  @参数 title要显示的文字
 * 	@输出 表头，直接在网页上显示
 **/
 function result_header($title){
 	?>
 	<div class="title"><?php echo $title;?></div>
 	<table class="nosortable" style="table-layout: fixed;overflow: hidden;text-overflow: ellipsis; word-wrap: break-word;">
 		<thead>
	 	<tr>
	 		<th width="50px">序号</th>
	 		<th width="75px">日期</th>
	 		<th>投料批号</th>
	 		<th  width="70px">客户</th>
	 		<th width="70px">规格</th>
	 		<th>产品批号</th>
	 		<th width="48px">重量</th>
	 		<th width="48px">模具</th>
	 		<th width="48px">伤点</th>
	 		<th width="100px">表面</th>
	 		<th width="80px">判定结果</th>
	 		<th width="100px">备注</th>
 		</tr>
 		</thead>
 		<tbody id="presult">
 <?php }
 
 /** @todo 生产预输入，减少重复劳动
  *  @参数 无
  *  @输出 html输出页面
  **/
 function prepare_edit(){ 
 	global $arr_spec,$database;
	 ?>
 	<div class="pe">
 	<fieldset>
	 <legend align="center">生产记录预输入</legend>
	 <table>
	 	<form name="prepare_edit" action="<?php echo $database->arr_config_r[0];?>action/produce.php?action=edit" onsubmit="return check_prepedit()" method="post">
			 <tr><td><label for="preclient">客户*</label></td>
				<td><input name="preclient" type="text" id="preclient" style="text-align:center;" maxlength="40" size="10"/></td></tr>
				<tr><td><label for="prespec">规格*</label></td>
				<td><select name="prespec" style="text-align:center;">
					<?php
					$i=0; 
					while (isset($arr_spec[$i])){ ?>
						<option value="<?php echo $arr_spec[$i];?>" ><?php echo $arr_spec[$i];?></option>
					<?php ++$i;} ?>	
				</select></td></tr>					
				<tr><td><label for="prerog">投料批号*</label></td>
				<td><input name="prerog" type="text" id="prerog" style="text-align:center;" maxlength="12" size="12"/></td></tr>			
				<tr><td><label for="preproduct">产品批号*</label></td>
				<td><input name="preproduct" type="text" id="preproduct" style="text-align:center;" maxlength="12" size="12"/></td></tr>
				 
				<tr><td><label for="prenum">记录数*</label><td><input name="prenum" type="text" id="prenum" style="text-align:center;" maxlength="3" size="3"/></td></tr>
				<tr><td><label for="premium">溢料重量</label><td><input name="premium" type="text" id="premium" style="text-align:center;" maxlength="8" size="5"/></td></tr>
				<tr><td></td><td><button type="submit" class="positive">继 续</button></td></tr>
		 </form>
		 </table>
		 </fieldset>
	 </div>
 <?php }
 
/** @todo 生产预输入，减少重复劳动
  *  @参数 无
  *  @输出 html输出页面
  **/
 function prerog_edit(){ 
 	global $arr_spec,$database;
	 ?>
 	<div class="pe">
 	<fieldset>
	 <legend align="center">原材料记录预输入</legend>
	 <table>
	 	<form name="prepare_edit" action="<?php echo $database->arr_config_r[0];?>action/rog.php?action=input" onsubmit="return check_preroginput()" method="post">
				<tr><td><label for="preraw">首个原料批号*</label></td><td><input name="preraw" id="preraw" value="YA<?php echo datetostring(date("Y-m-d"));?>0101" /></td></tr>
				<tr><td><label for="prespec">规格*</label></td>
				<td><select name="prespec" style="text-align:center;">
					<option value="12.5">12.5</option>
					<option value="12">12</option>
					<option value="9.5">9.5</option>
				</select></td></tr>
				<tr><td><label for="prenum">记录数*</label><td><input name="prenum" type="text" id="prenum" style="text-align:center;" maxlength="3" size="3"/></td></tr>
				<tr><td></td><td><button type="submit" class="positive">继 续</button></td></tr>
		 </form>
		 </table>
		 </fieldset>
	 </div>
 <?php }

  /** @todo 生产输入
  *  @参数 日期，客户，规格，投料，班，组，项目数
  *  @输出 html输出页面
  **/
 function produce_edit($edate,$eclient,$espec,$erog,$eproduct,$enum){ 
 	global $arr_spec,$database;
	 ?>
	 <div class="edit">
	 <fieldset style="border: medium none;">
 	<legend align="center">生产记录输入</legend>
 	<table style="width:100%" id="ptable"><!--ptable非css--><thead><tr><td>客户</td><td>规格</td><td>投料批号</td><td>产品批号</td><td>重量</td><td>模具</td><td>伤点</td><td>表面</td><td>判定结果</td><td>备注</td></tr></thead>
	 	<form name="edit" action="<?php echo $database->arr_config_r[0];?>action/produce.php?action=write" method="post">
	 	<?php 
		 $pstartnum = substr($eproduct,-1,1);
		 for ($i=$pstartnum,$k=1;$i<$enum + $pstartnum;++$i,++$k){?>
		 	 <tr id="<?php echo "row" . $k;?>"><td>
			  <input name="eclient<?php echo $k;?>" type="text" style="width:40px" id="eclient<?php echo $k;?>" value="<?php echo $eclient;?>" style="text-align:center;" maxlength="40" size="10" onblur="xml_check('eclient',<?php echo $k;?>)"/><img id="eclient_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/>
				</td><td>
				<select name="espec<?php echo $k;?>" style="text-align:center;width:90px">
					<?php
					$j=0; 
					while (isset($arr_spec[$j])){ ?>
						<option value="<?php echo $arr_spec[$j];?>"  <?php  if ($arr_spec[$j] == $espec) echo 'selected="selected"';?> ><?php echo $arr_spec[$j];?></option>
					<?php ++$j;} ?>	
				</select>				
				</td><td>
				<input name="erog<?php echo $k;?>" type="text" style="width:100px" id="erog<?php echo $k;?>" value="<?php echo $erog;?>" style="text-align:center;" maxlength="12" size="12" onblur="xml_check('erog',<?php echo $k;?>,'rog')"/><img id="erog_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/>
				</td><td> 
				<?php 
				if (strlen($i) ==1)
					$num = "0" . $i;
				else
					$num = $i;
				?>
				<input name="eproduct<?php echo $k;?>" type="text" id="eproduct<?php echo $k;?>" value="<?php  echo substr($eproduct,0,10) . $num;?>" style="text-align:center;width:100px" maxlength="12" size="12" onblur="xml_check('eproduct',<?php echo $k;?>,'product')"/><img id="eproduct_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle" onmouseover="null" />
				</td><td>
				<input name="eweight<?php echo $k;?>" type="text" id="eweight<?php echo $k;?>" style="text-align:center;width:40px" maxlength="4" size="4" onblur="xml_check('eweight',<?php echo $k;?>,'weight')"/><img id="eweight_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/>
				</td><td>
				<input name="emould<?php echo $k;?>" type="text" id="emould<?php echo $k;?>" style="text-align:center;width:30px" maxlength="3" size="3" onblur="xml_check('emould',<?php echo $k;?>,'mould')"/><img id="emould_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/>
				</td><td>
				<input name="edefect<?php echo $k;?>" type="text" id="edefect<?php echo $k;?>" style="text-align:center;width:30px;" maxlength="3" size="3" onblur="xml_check('edefect',<?php echo $k;?>,'defect')"/><img id="edefect_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/>
				</td><td> 
				<input name="esurface<?php echo $k;?>" type="text" id="esurface<?php echo $k;?>" style="text-align:center;" maxlength="40" size="10"/>
				</td><td> 
				<select style="text-align:center;width:70px;" name="ejudge<?php echo $k;?>" id="ejudge<?php echo $k;?>">
					<option value="合格">合格</option>
					<option value="不合格">不合格</option>
					<option value="待检">待检</option>
				</select></td><td>
				<input name="eremarks<?php echo $k;?>" type="text" id="eremarks<?php echo $k;?>" style="text-align:center;" maxlength="40" size="10" onblur="xml_check('eremarks',<?php echo $k;?>)"/><img id="eremarks_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/></td>				
				</tr> <?php } ?></table>
				<div style="text-align:center;">
				<button type="button" class="positive" onclick="check_pedit()">检 查</button>&nbsp;&nbsp;
				<button type="submit" class="positive" onclick="document.getElementById('tr_rows').value=document.getElementById('ptable').rows.length-1">提 交</button></div>
				<input type="hidden" name="tr_rows" id="tr_rows" value="<?php echo $enum;?>" />
		 </form>
	 </div>
 <?php }
 
  /** @todo 生产输入
  *  @参数 日期，客户，规格，投料，班，组，项目数
  *  @输出 html输出页面
  **/
 function pack_edit(){ 
 	global $database;
	 ?>
	 <div class="edit">
	 <fieldset style="border: medium none;">
 	<legend align="center">问题产品提交</legend>
 	<table style="width:500px;"><thead><tr><td>工序</td><td>产品批号</td><td>判定结果</td><td>备注</td></tr></thead>
	 	<form name="edit" action="<?php echo $database->arr_config_r[0];?>action/produce.php?action=packsubmit" method="post"><tbody id="ptbody"><!--ptable非css-->
	 	<?php 
		 for ($k=1;$k<=3;++$k){?>
		 	 <tr id="<?php echo "row" . $k;?>"><td>
			  	<select style="text-align:center;width:70px;" name="epack<?php echo $k;?>">
					<option value="包装">包装</option>
					<option value="销售">销售</option>
				</select>
			  </td><td>
				<input name="eproduct<?php echo $k;?>" type="text" style="text-align:center;width:100px" maxlength="12" size="12"/><img src="../images/check_blank.gif" align="absmiddle" onmouseover="null" />
				</td><td> 
				<select style="text-align:center;width:70px;" name="ejudge<?php echo $k;?>">
					<option value="合格">合格</option>
					<option value="不合格" selected="selected">不合格</option>
					<option value="待检">待检</option>
				</select></td><td>
				<input name="eremarks<?php echo $k;?>" type="text" style="text-align:center;" maxlength="40" size="10"/><img src="../images/check_blank.gif" align="absmiddle"/>
				</td><td vAlign="center"><button type="button" class="positive" style="margin-top:0;padding:3px 4px 0 4px" onclick="addrow()">添加</button></td>
				</tr> <?php } ?></tbody></table>
				<div style="text-align:center;">
				<button type="button" class="positive" onclick="check_pack()">检 查</button>&nbsp;&nbsp;
				<button type="submit" class="positive">提 交</button></div>
		 	</form>
	 </div>
 <?php }
 
 /** @todo 生产输入
  *  @参数 日期，客户，规格，投料，班，组，项目数
  *  @输出 html输出页面
  **/
 function rog_input($raw,$num){ 
 	global $arr_spec,$database;
	 ?>
	 <div class="edit">
	 <fieldset style="border: medium none;">
 	<legend align="center">原材料记录输入</legend>
 	<table style="width:100%" id="rtable"><!--ptable非css--><thead><tr><td>客户</td><td>规格</td><td>投料批号</td><td>产品批号</td><td>重量</td><td>模具</td><td>伤点</td><td>表面</td><td>判定结果</td><td>备注</td></tr></thead>
	 	<form name="edit" action="<?php echo $database->arr_config_r[0];?>action/produce.php?action=write" method="post">
	 	<?php 
		 $pstartnum = substr($eproduct,-1,1);
		 for ($i=$pstartnum,$k=1;$i<$enum + $pstartnum;++$i,++$k){?>
		 	 <tr id="<?php echo "row" . $k;?>"><td>
			  <input name="eclient<?php echo $k;?>" type="text" style="width:40px" id="eclient<?php echo $k;?>" value="<?php echo $eclient;?>" style="text-align:center;" maxlength="40" size="10" onblur="xml_check('eclient',<?php echo $k;?>)"/><img id="eclient_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/>
				</td><td>
				<select name="espec<?php echo $k;?>" style="text-align:center;width:90px">
					<?php
					$j=0; 
					while (isset($arr_spec[$j])){ ?>
						<option value="<?php echo $arr_spec[$j];?>"  <?php  if ($arr_spec[$j] == $espec) echo 'selected="selected"';?> ><?php echo $arr_spec[$j];?></option>
					<?php ++$j;} ?>	
				</select>				
				</td><td>
				<input name="erog<?php echo $k;?>" type="text" style="width:100px" id="erog<?php echo $k;?>" value="<?php echo $erog;?>" style="text-align:center;" maxlength="12" size="12" onblur="xml_check('erog',<?php echo $k;?>,'rog')"/><img id="erog_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/>
				</td><td> 
				<?php 
				if (strlen($i) ==1)
					$num = "0" . $i;
				else
					$num = $i;
				?>
				<input name="eproduct<?php echo $k;?>" type="text" id="eproduct<?php echo $k;?>" value="<?php  echo substr($eproduct,0,10) . $num;?>" style="text-align:center;width:100px" maxlength="12" size="12" onblur="xml_check('eproduct',<?php echo $k;?>,'product')"/><img id="eproduct_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle" onmouseover="null" />
				</td><td>
				<input name="eweight<?php echo $k;?>" type="text" id="eweight<?php echo $k;?>" style="text-align:center;width:40px" maxlength="4" size="4" onblur="xml_check('eweight',<?php echo $k;?>,'weight')"/><img id="eweight_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/>
				</td><td>
				<input name="emould<?php echo $k;?>" type="text" id="emould<?php echo $k;?>" style="text-align:center;width:30px" maxlength="3" size="3" onblur="xml_check('emould',<?php echo $k;?>,'mould')"/><img id="emould_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/>
				</td><td>
				<input name="edefect<?php echo $k;?>" type="text" id="edefect<?php echo $k;?>" style="text-align:center;width:30px;" maxlength="3" size="3" onblur="xml_check('edefect',<?php echo $k;?>,'defect')"/><img id="edefect_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/>
				</td><td> 
				<input name="esurface<?php echo $k;?>" type="text" id="esurface<?php echo $k;?>" style="text-align:center;" maxlength="40" size="10"/>
				</td><td> 
				<select style="text-align:center;width:70px;" name="ejudge<?php echo $k;?>" id="ejudge<?php echo $k;?>">
					<option value="合格">合格</option>
					<option value="不合格">不合格</option>
					<option value="待检">待检</option>
				</select></td><td>
				<input name="eremarks<?php echo $k;?>" type="text" id="eremarks<?php echo $k;?>" style="text-align:center;" maxlength="40" size="10" onblur="xml_check('eremarks',<?php echo $k;?>)"/><img id="eremarks_img<?php echo $k;?>" src="../images/check_blank.gif" align="absmiddle"/></td>				
				</tr> <?php } ?></table>
				<div style="text-align:center;">
				<button type="button" class="positive" onclick="check_pedit()">检 查</button>&nbsp;&nbsp;
				<button type="submit" class="positive" onclick="document.getElementById('tr_rows').value=document.getElementById('ptable').rows.length-1">提 交</button></div>
				<input type="hidden" name="tr_rows" id="tr_rows" value="<?php echo $enum;?>" />
		 </form>
	 </div>
 <?php }

 /* 原料批号长度与正则校验 */
 function is_rog($rog_num){
 	if (strlen($rog_num) != 12)
	 	return false;
 	$re_rog = '/[Y,T][A-Z][0,1][8,9,0,1][0,1][0-9][0-3][0-9]0[0-3][0-9][0-9]/i';//原料批号牌号现在是0-3,年份为09,10年或者11年
 	if (preg_match($re_rog,$rog_num))
 		return true;
 	else
 		return false;
}
/**
 * @todo 产品批号长度与正则校验
 * @参数 产品批号
 * @输出 不正确输出flase 
 * 
 **/
 function is_product($product_num){
 	if (strlen($product_num) != 12)
	 	return false;
 	$date_f_p='20' . substr($product_num,0,2).'-'.substr($product_num,2,2).'-'.substr($product_num,4,2);
	if(!is_date($date_f_p))
		return false;
 	$re_product = '/[0,1][0,9][0,1][0-9][0-3][0-9][0,1][1-9][A-C][A-K][0-9][0-9]/i';
 	if (preg_match($re_product,$product_num))
 		return true;
 	else
 		return false;
 }
 /**
 * @todo 模具正则校验
 * @参数 模具批号
 * @输出 不正确输出flase 
 **/
 function is_mould($mould){
	if (strlen($mould) != 3)
	 	return false;
	$re_mould = '/\d{3}/';
	if(preg_match($re_mould,$mould))
		return true;
	else
		return false;
 }
 
 
/**
 * @todo 校验数组元素重复
 * @参数 数组
 * @输出 重复输出flase 
 * 
 **/
 function duplicate($array){
 	if(array_flip(array_flip($array))==$array)
 		return true;//不重复
	return false; 		
 }
 /**
 * @todo 校验表单元素是否是正整数(包括0)或者正浮点数(包括0)
 * @参数 数据，标识符（1为整数，0为浮点数）
 * @输出 正确返回true
 **/
 function is_number($num,$tag){
 	if($tag){
 		if((string)(int)$num===(string)$num && (int)$num>=0)
 			return true;
		else
			return false;
 	}else{
 		if((string)(float)$num===(string)$num && (float)$num>=0)
 			return true;
		else
			return false;
 	}
 }
 /** @todo 提取生产批号中或原材料批号中的日期
  *  @参数 生产批号或者原材料批号,type=rog or product
  *  @输出 XXXX-XX-XX的日期 
  **/
  function string_to_date($lot,$type){
  	if ($type=='rog'){
  		$date_pe=substr($lot,2,2) . '-' . substr($lot,4,2) . '-' . substr($lot,6,2);
		$date_jie=date('Y-m-d',strtotime($date_pe));
		return $date_jie;
  	}elseif($type=='product'){
  		$date_pe=substr($lot,0,2) . '-' . substr($lot,2,2) . '-' . substr($lot,4,2);
		$date_jie=date('Y-m-d',strtotime($date_pe));
		return $date_jie;
  	}else
  		die('日期获取失败，请检查string_to_date函数');
  }
  
 /** @todo session函数，用来验证用户权限,这是一个类似于二进制位数来验证的方式，即10位数，每位表示一个权限，如果该位为1，即为有些权限
   * @参数 $bin 权限位次0，1，2，3，4，5	 管理员 0  技术 1  生产 2  实验 3  原材料 4  包装 5	第二个参数表示是跳出现在PHP脚本并显示错误页面还是返回值，默认为显示错误
   * @输出 使用函数login_echo转至相应页面
   **/
 function check_rights($bin,$echo=1){
 	global $database;
	if(!isset($_SESSION['rights']) || substr($_SESSION['rights'],$bin,1)!='1'){
		if($echo){
			check_user();
			login_echo($database->arr_config_r[0],"对不起，你没有权限查看此页");
		}else
			return false;	
	}else{
		check_user();
		return true;
	}
 }
 
  /** @todo session函数，用来验证用户
   * @参数 无
   * @输出 验证成功无动作，否则使用函数login_echo转至登陆页面
   **/
  function check_user(){
  	global $database;
	if(!(isset($_SESSION['userid']) && isset($_SESSION['rights']))){
		login_echo($database->arr_config_r[0]. "admin/login.php?log=login","请先登陆");
	}
  }
  
/** @todo 原材料查询表单
  * @参数 无
  *	@输出 表单页
  **/
  function rogForm($begin=0,$end=0,$supplier=0,$make=0,$spec=0,$judge=0,$is_edit=0){
global $arr_spec,$database;?>
 	<div class="log">
 	<fieldset>
 	<legend align="center"><?php if($is_edit) echo '修改范围'; else echo '原材料记录查询';?></legend>
	 <table>
		<form id="rform"  action="<?php echo $database->arr_config_r[0];?>action/rog.php?action=<?php if($is_edit) echo 'rogedit';?>query" onsubmit="return check_rogform()" method="post"> <!--发送数据到..-->
		<tr>
		  <td><label for="rbegin">进货日期*</label></td>
		  <td><input name="rbegin" type="text" id="rbegin" value="<?php echo $begin;?>" onfocus="WdatePicker({isShowClear:false,readOnly:true})" size="10" maxlength="10" /></td>
		  <td><label for="rend" style="text-align:center">至</label></td>
  		  <td><input name="rend" type="text" id="rend" value="<?php echo $end;?>" onfocus="WdatePicker({isShowClear:false,readOnly:true})" size="10" maxlength="10" readonly="readonly"/></td>
  		</tr>
  		<tr>
		  <td><label for="rsupplier">厂家代码</label></td>
		  <td><input id="rsupplier" name="rsupplier"/></td>
  		</tr>
  		<tr>
		  <td><label for="rmaker">牌号</label></td>
		  <td>
		  	<select style="text-align:center;" name="rmake" id="rmake">
					<option value="0" <?php if ($make==0) echo "selectd";?>>全部</option>
					<option value="1060">1060</option>
					<option value="1100">1100</option>
					<option value="3003">3003</option>
					<option value="GD02">GD02</option>
					<option value="1050">1050</option>
					<option value="1050A">1050A</option>
					<option value="1070">1070</option>
			</select>
		  </td>
	  	</tr>
		<tr>
			<td><label for="rspec">规格</label></td>
			<td>
				<select style="text-align:center;" name="spec" id="spec" >
					<option value="0" <?php if ($spec==0) echo "selectd";?>>全部</option>
					<option value="12.0">12.0</option>
					<option value="12.5">12.5</option>
					<option value="9.5">9.5</option>
				</select>
			</td>
		</tr>
		<tr>
			<td><label for="rjudge">判定结果</label></td>
			<td><select style="text-align:center;" name="rjudge" >
					<option value="0" <?php if ($judge==0) echo "selectd";?>>全部</option>
					<option value="合格">合格</option>
					<option value="不合格">不合格</option>
				</select></td></tr>
				<tr><td></td><td></td><td><button type="submit" class="positive">提 交</button></td></tr>
			</form>
			</table>
			</fieldset>			 		
		 </div>
 	<?php }
 	/** @todo 输出查询结果表头
 *  @参数 title要显示的文字
 * 	@输出 表头，直接在网页上显示
 **/
 function rog_header($title){
 	?>
	<div id="suoding">&nbsp;</div><!--锁定窗口-->
 	<div class="title"><?php echo $title;?></div>
 	<table class="nosortable" style="table-layout: fixed;overflow: hidden;text-overflow: ellipsis; word-wrap: break-word;">
 		<thead>
	 	<tr>
	 		<th width="39px">序号</th>
	 		<th width="60px">日期</th>
	 		<th width="39px">厂家</th>
	 		<th width="39px">牌号</th>
	 		<th width="39px">规格</th>
	 		<th width="48px">重量</th>
	 		<th width="75px">供货批号</th>
	 		<th width="75px">原料批号</th>
	 		<th width="75px">抗拉强度</th>
	 		<th width="45px">伸长率</th>
	 		<th width="75px">退火</th>
	 		<th width="60px">判定结果</th>
      <th width="100px">备注</th>
 		</tr>
 		</thead>
 		<tbody id="rresult">
 <?php }

	/* @todo 检测是否字母与数字,不区分大小写,只限一个字符，长度大于1直接返回false
	@参数 $value(检测的值),[$type] (默认为alpha(字母),另外一个为num(数字)）
	@返回 true or false
	*/
	function checksingle($value,$type="alpha") {
		if(strlen($value)!=1)
			Return false;
		$alpha_arr=array(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z);
		$num_arr=array(0,1,2,3,4,5,6,7,8,9);
		if($type=="alpha"){
			return in_array(strtolower($value),$alpha_arr);
		}elseif($type=="num"){
			return in_array($value,$num_arr);
		}
	}
?>
